# import hmac, base64, struct, hashlib, time
#
#
# # 参数secretKey是开通google身份验证时的密钥
# def calGoogleCode(secretKey):
#     input = int(time.time()) // 30
#     key = base64.b32decode(secretKey)
#     msg = struct.pack(">Q", input)
#     googleCode = hmac.new(key, msg, hashlib.sha1).digest()
#     o = googleCode[19] & 15
#     googleCode = str((struct.unpack(">I", googleCode[o:o + 4])[0] & 0x7fffffff) % 1000000)
#     if len(googleCode) == 5:  # 如果验证码的第一位是0，则不会显示。此处判断若是5位码，则在第一位补上0
#         googleCode = '0' + googleCode
#     return googleCode
import random
import string


# import requests
#
# def verify_recaptcha(response_token, secret_key):
#     url = "https://www.google.com/recaptcha/api/siteverify"
#     params = {
#         "secret": secret_key,
#         "response": response_token  # 前端提交的验证码令牌
#     }
#     response = requests.post(url, data=params)
#     result = response.json()
#     return result.get("success", False)  # 返回验证结果（True/False）
#
# # 使用示例
# secret_key = "PU5LFBEGW2TPSGL6"
# user_token = "用户提交的 reCAPTCHA 令牌"  # 从前端表单获取
# is_valid = verify_recaptcha(user_token, secret_key)
# print("验证结果：", is_valid)



# import pyotp
#
#
# def GetGoogleCode():
# # 注意：此处的密钥必须是你自己 Google 账号的 2FA TOTP 密钥（需合法拥有）
#     google_2fa_secret = "PU5LFBEGW2TPSGL6"  # 格式通常为大写字母+数字，如 "JBSWY3DPEHPK3PXP"
#
# # 创建 TOTP 实例
#     totp = pyotp.TOTP(google_2fa_secret)
#
# # 生成当前实时验证码（每 30 秒更新一次）
#     current_code = totp.now()
#     return current_code


def random_name(self, length: int) -> str:
    # 生成随机字符串
    # 定义字符集：大小写字母 + 数字
    characters = string.ascii_letters + string.digits  # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    # 从字符集中随机选择length个字符，拼接成字符串
    random_str = ''.join(random.choice(characters) for i in range(length))
    return random_str
print(random_name(10))